using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class FollowTarget : MonoBehaviour
{
    [SerializeField] private float smoothSpeed;
    [SerializeField] private float maxPointX = 10;
    
    private Transform target;

    private void Update()
    {
        if (target != null)
        {
            Vector3 position = transform.position;
            position.x = target.position.x;

            position.x = Mathf.Clamp(position.x, 0, maxPointX);//将值限定在某个范围内
            
            transform.position = Vector3.Lerp(transform.position, position, Time.deltaTime * smoothSpeed);
        }
    }

    public void setTarget(Transform transform)
    {
        this.target = transform;
    }
}
